package com.springboot.demo.copy;

import com.springboot.demo.util.common.CopyUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.BeanUtils;

/**
 * 拷贝测试类
 *
 * @author supu
 * @create 2018-10-17 12:40
 **/
public class CopyDemo {

    public static void main(String[] args) {
        Person p1 = new Person();
        p1.setAge(20);
        p1.setName("zs");

        Person p2 = new Person();
        p2.setAge(21);
        p2.setName("ls");

        List<Person> srcList = new ArrayList<>(2);
        srcList.add(p1);
        srcList.add(p2);

       /* personList.removeIf(person -> "zs".equals(person.getName()));

        personList = personList.stream().filter(person -> "zs".equals(person.getName())).collect(Collectors.toList());*/

       /* personList = personList.stream().map(person -> {
            if( "zs".equals(person.getName())){
                person.setName("zs1");
            }
            return person;
        }).collect(Collectors.toList());*/

       /* personList.stream().filter(person -> "zs".equals(person.getName())).findFirst();

        personList.forEach(person -> System.out.println(person.getName()));*/

        /*String s = "1,2,3,4";

        String[] asArray = s.split(",");

        List<String> list = Arrays.asList(asArray);
        System.out.println("数量：" + list.size());
        list.forEach(str -> System.out.println(str) );*/

        List<Person> desList = CopyUtil.copyList(srcList);

//        desList.addAll(srcList);

        Person p3 = new Person();
        BeanUtils.copyProperties(p1,p3);
        p3.setAge(100);


        System.out.println("前 srcList " + srcList);
        System.out.println("前 desList " + desList);

        System.out.println("前 p1:" + p1);
        System.out.println("前 p3:" + p3);


        desList.stream().forEach(desPerson -> desPerson.setAge(99));

        System.out.println("*******************************");

        System.out.println("后 srcList " + srcList);
        System.out.println("后 desList " + desList);

        System.out.println("后 p1:" + p1);
        System.out.println("后 p3:" + p3);

        String uuid = UUID.randomUUID().toString();
        System.out.println("前 uuid：" + uuid);
        System.out.println("后 uuid：" + uuid.replace("-",""));
    }
}
